package s11;

import net.sf.cglib.core.KeyFactory;

/**
 * keyFactory类用来动态生成接口的实例，接口需要只包含一个newInstance方法，返回一个Object。keyFactory为构造出来的实例动态生成了Object.equals和Object.hashCode方法，能够确保相同的参数构造出的实例为单例的
 *
 * @author wangpp
 */
public class KeyFactoryTest {
    public static void main(String[] args) {
        KeyInterface key = (KeyInterface) KeyFactory.create(KeyInterface.class);
        Object foo = key.newInstance("foo", 42);
        Object bar = key.newInstance("foo", 42);
        System.out.println(foo);
        System.out.println(bar);

        System.out.println(foo == bar);
        System.out.println(foo.equals(bar));

        System.out.println(foo.hashCode());
        System.out.println(bar.hashCode());

        System.out.println(foo.getClass());


    }

//    @Test
//    public void testKeyFactory() throws Exception {
//        SampleKeyFactory keyFactory = (SampleKeyFactory) KeyFactory.create(SampleKeyFactory.class);
//        Object key = keyFactory.newInstance("foo", 42);
//        Object key1 = keyFactory.newInstance("foo", 42);
//        Assert.assertEquals(key, key1);//测试参数相同，结果是否相等
//    }
}
